refactor(tests): replace exec() with importlib in example runner#1628
refactor(tests): replace exec() with importlib in example runner#1628OfficialSerge wants to merge 4 commits intoNVIDIA:mainfrom
Conversation
| # Collect metadata for file 'module_name' located at 'fullpath'. | ||
| # CASE: file does not exist -> spec is none. | ||
| # CASE: file is not .py -> spec is none. | ||
| # CASE: file does not have proper loader (module.spec.__loader__) -> spec.loader is none. |
There was a problem hiding this comment.
I don't think we necessarily need to duplicate information from the Python stdlib docs here, but don't feel strongly either way.
There was a problem hiding this comment.
I see, my ruff linter was flagging it as a potential point of runtime failure, the if-none check fixed these issues though I figured I'd leave an explanation to help people understand the need for the check, in case there are any future revisions.
There was a problem hiding this comment.
This seems a bit more complicated than necessary...? Assuming we always have main (#1664), can we simplify the logic here after merging the other PR?
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
| def test_example(self, example, deinit_cuda): | ||
| run_example(samples_path, example) | ||
| if Device().device_id != 0: | ||
| Device(0).set_current() |
There was a problem hiding this comment.
We should kick off CI and check if removing this line is OK. IIRC on a multi-GPU system it would fail without this.
Description
This PR is in response to the following TODO item in
cuda_core/tests/example_tests/utils.py.Key Changes
run_exampleinutils.pyusingimportlib, adding support for bothmain()andexec()scripts, tracebacks should now provide real line number feedback, thus paving the way for us to progressively enhance the remaining non-module tests and examples.test_basic_example.pyto usepathlib.Pathinstead ofos.path.join().Device(0)andset_current()calls in test class, instead relying on exitingdeinit_cuda()fixture for consistent teardowns (seeconftest.py)Next Steps
main()and refactor them into Python modules, some examples are currently refactored while others are still plain executables so it's a mix.